package CtrlLayer;
import java.util.ArrayList;
import ModelLayer.*;

public class ContractorController
{

    private ContractorContainer contractorContainer;

    public ContractorController()
    {
       contractorContainer = ContractorContainer.getInstance();
    }

  
    public void createContractorObjects(){  
       contractorContainer.addContractor(new Contractor(10000,"Minzuhar", "ccc@cc.cc", "1235436537", "IBAN21987471"));
       contractorContainer.addContractor(new Contractor(10001,"Zumbul", "ccc@cc.cc", "1248721488", "IBAN2543634"));
       contractorContainer.addContractor(new Contractor(10000,"Margarita", "ccc@cc.cc", "32565475", "IBAN7653456"));
    }

        
    public boolean createContractor(int id, String name, String email,String phoneNumber, String bankAccount){
        boolean added = false;
        if(findContractor(id) == null) {
            contractorContainer.addContractor(new Contractor(id, name, email, phoneNumber, bankAccount));
            added = true;
        } else {
            added = false;
        }
        return added;
    }

    public Contractor findContractor(int id){    
        return  contractorContainer.findContractorById(id);
    }

     public void deleteContractor(int id){
        contractorContainer.deleteContractor(contractorContainer.findContractorById(id));
    }
    
     public void updateContractor(int id, String name, String email,String phoneNumber, String bankAccount){
        Contractor contractor =  contractorContainer.findContractorById(id);
        if(contractor != null){
            contractorContainer.findContractorById(id).setName(name);
            contractorContainer.findContractorById(id).setEmail(email);
            contractorContainer.findContractorById(id).setPhoneNumber(phoneNumber);
            contractorContainer.findContractorById(id).setBankAccount(bankAccount);
        }
    }
    
}
